#-*- codeing = utf-8 -*-
#@Time : 2020/7/13 22:33
#@Author : 阳某
#@File : 异常处理.py
#@Software : PyCharm

'''
#捕获异常
try:
    print("-------test-----1---")
    f = open("123.txt","r")#用只读模式打开一了一文件，报错
    print("-------test-----2---")
except IOError:  #文件没找到属于IO异常，输入输出异常
    pass
'''
'''
try:
    print("-------test-----1---")
    f = open("123.txt", "r")  # 用只读模式打开一了一文件，报错
    print("-------test-----2---")
    
    print(num)
except (NameError,IOError):
    print("产生错误了")

'''
'''
try:
    print(num)

    print("-------test-----1---")
    f = open("123.txt", "r")  # 用只读模式打开一了一文件，报错
    print("-------test-----2---")
except (NameError, IOError):
    print("产生错误了")
'''
'''
#获取错误描述
try:
    print(num)

    print("-------test-----1---")
    f = open("123.txt", "r")  # 用只读模式打开一了一文件，报错
    print("-------test-----2---")
except (NameError, IOError) as result:
    print("产生错误了")
    print(result)
'''
'''
#捕获所有异常
try:
    print(num)

    print("-------test-----1---")
    f = open("123.txt", "r")  # 用只读模式打开一了一文件，报错
    print("-------test-----2---")
except Exception as result:  #Exception可以补货所有异常
    print("产生错误了")
    print(result)
'''
import time
#try   finally
try:
    f = open("123.txt","r")
    try:
        while True:
            content = f.readline()
            if len(content)==0:
                break
            time.sleep(2)
            print(content)
    finally:
        f.close()
        print("文件关闭")
except Exception as result:
    print("发生异常....")












